//
// Created by Arikes on 9/25/21.
//

#ifndef DESIGNERMODE_HANDLER_H
#define DESIGNERMODE_HANDLER_H

#include <iostream>
#include <string>
namespace ChainOfResponsibilityMode
{
    class Handle
    {
    public:
        void setNext(Handle* nextHandle)
        {
            _nextHandle = nextHandle;
        }

        Handle* getNext()
        {
            return _nextHandle;
        }

        virtual void handleRequest(std::string request) = 0;
    private:
        Handle* _nextHandle = nullptr;
    };


    class ConcreteHandler1:public Handle
    {
    public:
        virtual void handleRequest(std::string request)
        {
            if (request == "one")
                std::cout<<"具体处理者1负责处理该请求！"<<std::endl;
            else
            {
                if (getNext() != nullptr) {
                    getNext()->handleRequest(request);
                } else {
                    std::cout<<"没有人处理该请求！"<<std::endl;
                }
            }
        }
    };

    class ConcreteHandler2:public Handle
    {
    public:
        virtual void handleRequest(std::string request)
        {
            if (request == "two")
                std::cout<<"具体处理者2负责处理该请求！"<<std::endl;
            else
            {
                if (getNext() != nullptr) {
                    getNext()->handleRequest(request);
                } else {
                    std::cout<<"没有人处理该请求！"<<std::endl;
                }
            }
        }
    };

    class ConcreteHandler3:public Handle
    {
    public:
        virtual void handleRequest(std::string request)
        {
            if (request == "three")
                std::cout<<"具体处理者3负责处理该请求！"<<std::endl;
            else
            {
                if (getNext() != nullptr) {
                    getNext()->handleRequest(request);
                } else {
                    std::cout<<"没有人处理该请求！"<<std::endl;
                }
            }
        }
    };
}

#endif //DESIGNERMODE_HANDLER_H
//ChainOfResponsibilityMode::Handle* handle1 = new ChainOfResponsibilityMode::ConcreteHandler1;
//ChainOfResponsibilityMode::Handle* handle2 = new ChainOfResponsibilityMode::ConcreteHandler2;
//ChainOfResponsibilityMode::Handle* handle3 = new ChainOfResponsibilityMode::ConcreteHandler3;
//handle1->setNext(handle2);
//handle2->setNext(handle3);
//handle1->handleRequest("three");